﻿using System;
using System.Runtime.InteropServices;

namespace DotnetSpider.Core.Infrastructure
{
	/// <summary>
	/// Windows Form 帮助类
	/// </summary>
	public static class WindowsFormUtil
	{
		/// <summary>
		/// 查找窗口句柄
		/// </summary>
		/// <param name="lpClassName"></param>
		/// <param name="lpWindowName"></param>
		/// <returns></returns>
		[DllImport("User32.dll", EntryPoint = "FindWindow")]
		public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

		/// <summary>
		/// 查找窗口句柄
		/// </summary>
		/// <param name="hwndParent"></param>
		/// <param name="hwndChildAfter"></param>
		/// <param name="lpClassName"></param>
		/// <param name="lpWindowName"></param>
		/// <returns></returns>
		[DllImport("User32.dll", EntryPoint = "FindWindowEx")]
		public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);

		/// <summary>
		/// 给指定句柄发消息
		/// </summary>
		/// <param name="hwnd"></param>
		/// <param name="wMsg"></param>
		/// <param name="wParam"></param>
		/// <param name="lParam"></param>
		/// <returns></returns>
		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

		/// <summary>
		/// 关闭窗口的信号
		/// </summary>
		public const int WmClose = 0x10;
	}
}

